#!/bin/bash

# postinst script for system-boot-grub
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        chown root:sys $BASEDIR/boot
	chown root:sys $BASEDIR/boot/grub
	chown root:sys $BASEDIR/boot/grub/bin
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/default ] && rm -f $BASEDIR/boot/grub/default
	else
	    [ -f $BASEDIR/boot/grub/default ] || cp -ax $BASEDIR/usr/share/doc/system-boot-grub/examples/default $BASEDIR/boot/grub/default
	    chmod 0444 "$BASEDIR/boot/grub/default"
	    chown root:sys "$BASEDIR/boot/grub/default"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/capability ] && rm -f $BASEDIR/boot/grub/capability
	else
	    chmod 0444 "$BASEDIR/boot/grub/capability"
	    chown root:sys "$BASEDIR/boot/grub/capability"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/bin/grub ] && rm -f $BASEDIR/boot/grub/bin/grub
	else
	    chmod 0555 "$BASEDIR/boot/grub/bin/grub"
	    chown root:sys "$BASEDIR/boot/grub/bin/grub"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/sbin/installgrub ] && rm -f $BASEDIR/sbin/installgrub
	else
	    chmod 0555 "$BASEDIR/sbin/installgrub"
	    chown root:sys "$BASEDIR/sbin/installgrub"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/menu.lst ] && rm -f $BASEDIR/boot/grub/menu.lst
	else
	    [ -f $BASEDIR/boot/grub/menu.lst ] || cp -ax $BASEDIR/usr/share/doc/system-boot-grub/examples/menu.lst $BASEDIR/boot/grub/menu.lst
	    chmod 0644 "$BASEDIR/boot/grub/menu.lst"
	    chown root:sys "$BASEDIR/boot/grub/menu.lst"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/e2fs_stage1_5 ] && rm -f $BASEDIR/boot/grub/e2fs_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/e2fs_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/e2fs_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/fat_stage1_5 ] && rm -f $BASEDIR/boot/grub/fat_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/fat_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/fat_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/ffs_stage1_5 ] && rm -f $BASEDIR/boot/grub/ffs_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/ffs_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/ffs_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/install_menu ] && rm -f $BASEDIR/boot/grub/install_menu
	else
	    chmod 0644 "$BASEDIR/boot/grub/install_menu"
	    chown root:sys "$BASEDIR/boot/grub/install_menu"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/iso9660_stage1_5 ] && rm -f $BASEDIR/boot/grub/iso9660_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/iso9660_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/iso9660_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/jfs_stage1_5 ] && rm -f $BASEDIR/boot/grub/jfs_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/jfs_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/jfs_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/minix_stage1_5 ] && rm -f $BASEDIR/boot/grub/minix_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/minix_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/minix_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/nbgrub ] && rm -f $BASEDIR/boot/grub/nbgrub
	else
	    chmod 0644 "$BASEDIR/boot/grub/nbgrub"
	    chown root:sys "$BASEDIR/boot/grub/nbgrub"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/pxegrub ] && rm -f $BASEDIR/boot/grub/pxegrub
	else
	    chmod 0644 "$BASEDIR/boot/grub/pxegrub"
	    chown root:sys "$BASEDIR/boot/grub/pxegrub"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/reiserfs_stage1_5 ] && rm -f $BASEDIR/boot/grub/reiserfs_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/reiserfs_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/reiserfs_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/splash.xpm.gz ] && rm -f $BASEDIR/boot/grub/splash.xpm.gz
	else
	    chmod 0644 "$BASEDIR/boot/grub/splash.xpm.gz"
	    chown root:sys "$BASEDIR/boot/grub/splash.xpm.gz"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/stage1 ] && rm -f $BASEDIR/boot/grub/stage1
	else
	    chmod 0644 "$BASEDIR/boot/grub/stage1"
	    chown root:sys "$BASEDIR/boot/grub/stage1"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/stage2 ] && rm -f $BASEDIR/boot/grub/stage2
	else
	    chmod 0644 "$BASEDIR/boot/grub/stage2"
	    chown root:sys "$BASEDIR/boot/grub/stage2"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/stage2_eltorito ] && rm -f $BASEDIR/boot/grub/stage2_eltorito
	else
	    chmod 0644 "$BASEDIR/boot/grub/stage2_eltorito"
	    chown root:sys "$BASEDIR/boot/grub/stage2_eltorito"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/ufs2_stage1_5 ] && rm -f $BASEDIR/boot/grub/ufs2_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/ufs2_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/ufs2_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/ufs_stage1_5 ] && rm -f $BASEDIR/boot/grub/ufs_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/ufs_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/ufs_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/vstafs_stage1_5 ] && rm -f $BASEDIR/boot/grub/vstafs_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/vstafs_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/vstafs_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/xfs_stage1_5 ] && rm -f $BASEDIR/boot/grub/xfs_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/xfs_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/xfs_stage1_5"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/grub/zfs_stage1_5 ] && rm -f $BASEDIR/boot/grub/zfs_stage1_5
	else
	    chmod 0644 "$BASEDIR/boot/grub/zfs_stage1_5"
	    chown root:sys "$BASEDIR/boot/grub/zfs_stage1_5"
	fi
	# [ "$ZONEINST" = "1" ] || (mkdir -p $BASEDIR/usr/sbin && ln -f -s ../../sbin/installgrub $BASEDIR/usr/sbin/installgrub)
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

